a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
vis = [False] * 20
b = [0] * 20
ans = 0

def dfs(s, t):
    global ans
    if s == 12:
        if b[9] * b[10] == b[11]:
            ans += 1
        return

    # 剪枝条件
    if s == 3 and b[0] + b[1] != b[2]:
        return
    if s == 6 and b[3] - b[4] != b[5]:
        return
    if s == 9 and b[6] * b[7] != b[8]:
        return

    for i in range(t):
        if not vis[i]:
            vis[i] = True
            b[s] = a[i]
            dfs(s + 1, t)
            vis[i] = False

n = 13
dfs(0, n)
print(ans)
